package com.droid.mvvmlib.base;

import com.droid.framwork.ui.BaseFragment;
import com.droid.mvvmlib.log.Logcat;

/**
 *
 * @author zhyuc
 * @since  2019/9/19 12:04
 */
public class FragmentFactory {

    private final String TAG = "FragmentFactory";

    private static volatile FragmentFactory INSTANCE;

    public static FragmentFactory getInstance() {

        if (INSTANCE == null) {
            synchronized (ViewModelFactory.class) {
                if (INSTANCE == null) {
                    INSTANCE = new FragmentFactory();
                }
            }
        }
        return INSTANCE;
    }

    private FragmentFactory() {

    }

    /**
     * @param cls
     * @param <T>
     * @return
     */
    public <T extends BaseFragment> T createFragment(Class<T> cls) {
        try {
            return cls.newInstance();
        } catch (Exception e) {
            Logcat.e(TAG, "create fragment errror:"+e.getMessage());
        }
        return null;
    }
}
